package main
{
	import code.utils.TextFieldUtil;
	
	import com.darwin.darwinDll.Dll;
	import com.darwin.darwinMVC.core.CommonView;
	import com.darwin.darwinMVC.core.Context;
	import com.darwin.darwinMVC.mvc.DataSource;
	import com.darwin.darwinNet.Net;
	import com.darwin.darwinUI.core.UISkinProxy;
	import com.darwin.darwinUI.general.TextFieldFactory;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.Loader;
	import flash.text.TextField;

	/**
	 * 游戏初始化工作类。
	 * AppInit负责完成游戏的初始工作，包括整个游戏框架的建立
	 * @author lipi 
	 */
	public class AppInit
	{
		public function AppInit()
		{
			if(_instance == null)
			{
				_instance = this;
				_context = new Context();
			}
			else{throw new Error("实例化单例类出错-AppInit");}
		}
		
		private var _context:Context;
		
		private static var _instance:AppInit;
		
		public static function getInstance():AppInit
		{
			if(_instance == null)
				_instance = new AppInit();
			
			return _instance;
		}

		public function start():void
		{
			UISkinProxy.getInstance().adapter = new AppSkinAdapter();
			
			var FontLibrary:Class = Dll.getInstance().getSynPreloadRes("FontLib","FontLib");
			AppFont.fontClass = FontLibrary;
			AppFont.registerFont();
			
			
			var style:Class = Dll.getInstance().getSynPreloadRes("style","TEXTFIELD_STYLE","swf");
			var rule:XML = Dll.getInstance().getSynPreloadRes("rule","","xml");
//			TextFieldFactory.getInstance().registerStyle(style,rule,"DefaultFont","");
			TextFieldFactory.getInstance().registerStyle(style,rule,"DefaultFont","");
			
			var context:XML = Dll.getInstance().getSynPreloadRes("context","xml");
			UIManager.getLanguageManager().initialize(context);
//			var str:String = UIManager.getLanguageManager().getText("test");
//			var txt:TextField = TextFieldUtil.creatNormalTextField(str);
			_context.commonData = new AppCommonData();
			_context.commonView = new AppCommonView();
			_context.dataSource = new AppDataSource();
			
			UIManager.getPopUpManager().parent = (_context.commonView as AppCommonView).appContainer.popupLayer;
		}
		/*public function connectSever():void
		{
			AppNet.getInstance().connect(
				AppConfig.getInstance().socketHost,
				AppConfig.getInstance().socketPort
			);
			AppNet.getInstance().login("111","");
		}*/
		
	}
}